/**
 * Created by gongxun on 17/1/13.
 */

var PdkTableUILayer = GameCCSBase.extend({
    mPdkTableResultLayer: null,
    mPdkTableMicLayer: null,
    mPdkTablePlayerInfoLayer: null,
    mPdkTableChatLayer: null,
    mPdkTableSettingLayer: null,
    mPdkTableEndLayer: null,

    Panel_ready: null,
    Panel_caozuo: null,
    Image_userControlTips: null,
    Panel_playeAnim: null,

    mButton_bets: null,
    mPlayer: null,
    mPlayerPoss: null,
    mPlayerInfos: null,
    Panel_chat: null,

    //网络延迟
    mKwxSysInfoWidget: null,
    Image_ipwarring: null,

    //踢人按钮
    Button_kick1: null,
    Button_kick2: null,

    //叫btn
    mJiaoBtns: null,

    //当前操作玩家
    mCurrentSeat: null,
    Image_clock: null,
    AtlasLabel_clock: null,
    AtlasLabel_clockDt: null,

    //提示按钮
    Button_tishi: null,
    //出牌按钮
    Button_chupai: null,

    //当前推荐出牌的索引
    mTuijianIndex: null,

    ctor: function () {
        this._super();
        this.loadCocostudio("res/ccs/PdkUI.json");
        this.Panel_ready = mo.seekWidgetByName(this.ccsNode, "Panel_ready");
        this.Panel_caozuo = mo.seekWidgetByName(this.ccsNode, "Panel_caozuo");
        this.Image_userControlTips = mo.seekWidgetByName(this.ccsNode, "Image_userControlTips");
        this.Panel_playeAnim = mo.seekWidgetByName(this.ccsNode, "Panel_playeAnim");
        this.Button_kick1 = mo.seekWidgetByName(this.ccsNode, "Button_kick1");
        this.Button_kick2 = mo.seekWidgetByName(this.ccsNode, "Button_kick2");
        this.Image_ipwarring = mo.seekWidgetByName(this.ccsNode, "Image_ipwarring");
        this.Panel_chat = mo.seekWidgetByName(this.ccsNode, "Panel_chat");
        this.Image_clock = mo.seekWidgetByName(this.ccsNode, "Image_clock");
        this.AtlasLabel_clock = mo.seekWidgetByName(this.ccsNode, "AtlasLabel_clock");
        this.AtlasLabel_clock.ignoreContentAdaptWithSize(true);
        this.Button_chupai = mo.seekWidgetByName(this.ccsNode, "Button_chupai");
        this.Button_tishi = mo.seekWidgetByName(this.ccsNode, "Button_tishi");

        //设置
        mo.seekWidgetByName(this.ccsNode, "Button_setting").addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.mPdkTableSettingLayer.setDialog(true);
            }
        }, this);

        //规则
        mo.seekWidgetByName(this.ccsNode, "Button_rule").addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.addChild(new PdkTableRuleLayer());
            }
        }, this);

        mo.pdkCardHelper.initClockPos(mo.seekWidgetByName(this.ccsNode, "Panel_playCard"));

        this.loadUI();
    },

    onEnter: function () {
        this._super();

        mo.eventHelper.add("UserChatMsgResponse", this, function (userChatMsgResponse) {
            this.setChatMsg(userChatMsgResponse);
        });

        mo.eventHelper.add("UserOnLineChange", this, function (onlineInfo) {
            this.setPlayerOnlineStats(onlineInfo);
        });

        mo.eventHelper.add("UserChatMsgResponse_reward", this, function (userChatMsgResponse) {
            this.setChatMsgReward(userChatMsgResponse);
        });
    },

    onExit: function () {
        mo.eventHelper.remove(this);
        this._super();
    },

    loadUI: function () {
        if (cc.sys.isNative) {
            this.mPdkTableMicLayer = new PdkTableMicLayer();
            this.addChild(this.mPdkTableMicLayer);
        }

        //分数飘
        this.mPdkTableResultLayer = new PdkTableResultLayer();
        this.addChild(this.mPdkTableResultLayer);

        //个人信息
        this.mPdkTablePlayerInfoLayer = new KwxTablePlayerInfoLayer();
        this.addChild(this.mPdkTablePlayerInfoLayer);

        this.mPdkTableChatLayer = new KwxDialogChat();
        this.mPdkTableChatLayer.setChatButton(mo.seekWidgetByName(this.ccsNode, "Button_chat"), "pdk");
        this.addChild(this.mPdkTableChatLayer);

        this.mPdkTableSettingLayer = new KwxDialogSetting("pdk");
        this.addChild(this.mPdkTableSettingLayer);

        this.mPdkTableEndLayer = new PdkTableEndLayer();
        this.addChild(this.mPdkTableEndLayer);

        ///准备
        mo.seekWidgetByName(this.Panel_ready, "Button_start").addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.gameMsgManager.sendGameReadyRequestpdk();
            }
        }, this);

        //邀请
        mo.seekWidgetByName(this.Panel_ready, "Button_invite").addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pdkTable.onInvite();
            }
        }, this);

        //退出
        mo.seekWidgetByName(this.Panel_ready, "Button_disband").addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                var isStart = mo.pdkTable.mGameConfig.maxpan != mo.pdkTableStatus.mTableStatus.LeftPlayTimes;
                if (!isStart) {
                    mo.showMsgDialogOkAndCancel("确定退出房间吗？\n牌局未开始退出不会消耗房卡\n房主退出会解散牌桌", function () {
                        if (mo.pdkTable.mGameConfig.maxpan == mo.pdkTableStatus.mTableStatus.LeftPlayTimes) {
                            mo.gameMsgManager.sendForceExitTableRequestpdk();
                        }
                    }, this, function () {
                    }, this);
                }
                // mo.pdkTable.mPdkTableCancelLayer.sendCancelTableAgree();
            }
        }, this);

        //出牌
        this.Button_chupai.addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pdkTableStatus.onPlayCard();
            }
        }, this);

        //放弃
        this.Button_tishi.addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                mo.pdkTableStatus.setTuiJianChuPai(this.mTuijianIndex);
                this.mTuijianIndex++;
            }
        }, this);

        //踢人
        this.Button_kick1.addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(1);
            }
        }, this);

        this.Button_kick2.addTouchEventListener(function (sender, type) {
            if (mo.gameHelper.getIsTouchEnd(type)) {
                this.setKickPlayerForViewSeat(2);
            }
        }, this);

        ///用户
        this.mPlayer = [];
        this.mPlayerPoss = [];
        var Panel_player = mo.seekWidgetByName(this.ccsNode, "Panel_player");
        for (var i = 0; i < 3; i++) {
            var player = mo.seekWidgetByName(Panel_player, "Panel_player" + i);
            player.setTag(i);
            this.mPlayer.push(player);

            this.mPlayerPoss.push(cc.pAdd(player.getPosition(), cc.p(57, 140)));

            //初始化剩余牌数
            var Image_leftCard = mo.seekWidgetByName(player, "Image_leftCard");
            var AtlasLabel_leftNum = mo.seekWidgetByName(Image_leftCard, "AtlasLabel_leftNum");
            AtlasLabel_leftNum.ignoreContentAdaptWithSize(true);
            AtlasLabel_leftNum.setString("");

            player.addTouchEventListener(function (sender, type) {
                if (mo.gameHelper.getIsTouchEnd(type)) {
                    if (mo.pdkTable.mPlayerType == 0) {
                        return;
                    }

                    var index = sender.getTag();
                    var logicSeat = mo.pdkTableStatus.getLogicForView(index, mo.pdkTableStatus.mTableStatus.MySeat - 1) + 1;
                    var seatUser = mo.pdkTableStatus.mTableStatus["SeatUser" + logicSeat];
                    if (seatUser != null) {
                        this.mPdkTablePlayerInfoLayer.showPlayerInfo(index, seatUser.user_info, this.mPlayerPoss[index], logicSeat - 1);
                    }
                }
            }, this);

            player.showAddScoreAnim = function (score, delayTime) {
                var that = this;
                this.scheduleOnce(function (dt) {
                    var Panel_anim = mo.seekWidgetByName(that, "Panel_anim");
                    Panel_anim.setVisible(true);

                    var Text_score = mo.seekWidgetByName(that, "Text_score");


                    var Image_animBg0 = mo.seekWidgetByName(Panel_anim, "Image_animBg0");
                    var Image_animBg1 = mo.seekWidgetByName(Panel_anim, "Image_animBg1");
                    var Image_animBg2 = mo.seekWidgetByName(Panel_anim, "Image_animBg2");
                    var BitmapFontLabel_add = mo.seekWidgetByName(Panel_anim, "BitmapFontLabel_add");
                    var BitmapFontLabel_sub = mo.seekWidgetByName(Panel_anim, "BitmapFontLabel_sub");

                    Image_animBg0.setVisible(false);
                    Image_animBg1.setVisible(false);
                    Image_animBg2.setVisible(false);
                    BitmapFontLabel_add.setVisible(false);
                    BitmapFontLabel_sub.setVisible(false);

                    if (score > 0) {
                        var text = score >= 0 ? BitmapFontLabel_add : BitmapFontLabel_sub;

                        //分数
                        text.setVisible(true);
                        text.setOpacity(100);
                        text.setPosition(cc.p(0, 0));
                        text.setString("+s" + score);
                        var textPoxY = that.getTag() == 0 ? 50 : 80;
                        text.runAction(cc.sequence(
                            cc.spawn(
                                cc.moveTo(0.2, cc.p(0, textPoxY)),
                                cc.fadeIn(0.2)
                            ),
                            cc.callFunc(function () {
                                //改变分数
                                var currentScore = parseInt(Text_score.getString());
                                currentScore += score;
                                Text_score.setString(currentScore + "");
                            }),
                            cc.delayTime(1),
                            cc.hide()
                        ));

                        //背景0
                        Image_animBg0.setVisible(false);
                        Image_animBg0.runAction(cc.sequence(
                            cc.delayTime(0.2),
                            cc.show(),
                            cc.delayTime(0.4),
                            cc.hide()
                        ));

                        //背景0
                        Image_animBg1.setVisible(false);
                        Image_animBg1.setScale(1.0);
                        Image_animBg1.setOpacity(255);
                        Image_animBg1.runAction(cc.sequence(
                            cc.show(),
                            cc.spawn(
                                cc.scaleTo(0.4, 1.2),
                                cc.fadeOut(0.4)
                            )
                        ));

                        //背景0
                        Image_animBg2.setVisible(false);
                        Image_animBg2.setScale(1.0);
                        Image_animBg2.setOpacity(255);
                        Image_animBg2.runAction(cc.sequence(
                            cc.delayTime(0.3),
                            cc.show(),
                            cc.spawn(
                                cc.scaleTo(0.4, 1.4),
                                cc.fadeOut(0.4)
                            )
                        ));
                    } else {
                        var text = score >= 0 ? BitmapFontLabel_add : BitmapFontLabel_sub;

                        //分数
                        text.setVisible(true);
                        text.setOpacity(100);
                        text.setPosition(cc.p(0, 0));
                        text.setString("" + score);
                        var textPoxY = that.getTag() == 0 ? 50 : 80;
                        text.runAction(cc.sequence(
                            cc.spawn(
                                cc.moveTo(0.2, cc.p(0, textPoxY)),
                                cc.fadeIn(0.2)
                            ),
                            cc.callFunc(function () {
                                //改变分数
                                var currentScore = parseInt(Text_score.getString());
                                currentScore += score;
                                Text_score.setString(currentScore + "");
                            }),
                            cc.delayTime(1),
                            cc.hide()
                        ));
                    }
                }, delayTime);
            };
        }

        //wifi控件
        this.mKwxSysInfoWidget = new KwxSysInfoWidget();
        mo.seekWidgetByName(this.ccsNode, "Panel_wifi").addChild(this.mKwxSysInfoWidget);
    },

    //控制显示
    //index 1未开始  10:进来的状态 11:结算的状态
    //index 2打牌     20自己出牌 21别人出牌
    //index 3结束     30结束
    intoShowIndex: function (index) {
        this.Panel_ready.setVisible(false);
        this.Panel_caozuo.setVisible(false);
        this.Image_userControlTips.setVisible(false);

        if (index < 20) {
            if (index == 10) {
                this.Panel_ready.setVisible(false);
            } else if (index == 11) {
                this.Panel_ready.setVisible(true);

                var Button_start = mo.seekWidgetByName(this.ccsNode, "Button_start");
                var Button_invite = mo.seekWidgetByName(this.ccsNode, "Button_invite");
                var Button_disband = mo.seekWidgetByName(this.ccsNode, "Button_disband");

                //是否打了一局了
                var isPlay = mo.pdkTableStatus.mTableStatus.LeftPlayTimes != mo.pdkTable.mGameConfig.maxpan;
                Button_invite.setVisible(!isPlay);
                Button_disband.setVisible(!isPlay);

                //自己是否准备
                var myIsReady = mo.pdkTableStatus.getMyIsReady();
                if (myIsReady) {
                    this.mPdkTableEndLayer.setVisible(false);
                }

                Button_start.setVisible(!myIsReady);

                //短线重练的情况
                if (mo.pdkTable.mPlayGameCount != 0) {
                    Button_start.setVisible(false);
                }

                //准备按钮上面的文字
                if (!isPlay) {
                    Button_start.loadTextures("res/ccs/pdk/btn/btn_zhunbei1.png", "res/ccs/pdk/btn/btn_zhunbei2.png", "res/ccs/pdk/btn/btn_zhunbei3.png");
                } else {
                    Button_start.loadTextures("res/ccs/pdk/btn/btn_jixu1.png", "res/ccs/pdk/btn/btn_jixu2.png", "res/ccs/pdk/btn/btn_zhunbei3.png");
                }

                //处理同ip显示问题
                var ipEquals = mo.pdkTableStatus.getPlayerIpEqual();
                if (ipEquals.length > 0 && !isPlay) {
                    this.Image_ipwarring.setVisible(true);
                    for (var i = 0; i < 3; i++) {
                        var Panel_ip = mo.seekWidgetByName(this.Image_ipwarring, "Panel_ip" + i);
                        if (ipEquals.length > i) {
                            Panel_ip.setVisible(true);
                            mo.gameHelper.setTextString(mo.seekWidgetByName(Panel_ip, "Text_ip_nick"), ipEquals[i].nick);
                            mo.gameHelper.setTextString(mo.seekWidgetByName(Panel_ip, "Text_ip_ip"), ipEquals[i].ip);
                        } else {
                            Panel_ip.setVisible(false);
                        }
                    }
                } else {
                    this.Image_ipwarring.setVisible(false);
                }
            }

            //能否显示踢人
            if (mo.pdkTableStatus.mTableStatus != null && mo.pdkTable.mGameConfig != null) {
                var isPlay = mo.pdkTableStatus.mTableStatus.LeftPlayTimes != mo.pdkTable.mGameConfig.maxpan;
                var funcShowKick = function (viewSeat) {
                    if (isPlay) {
                        return false;
                    }

                    var logicSeat = mo.pdkTableStatus.getLogicForView(viewSeat, mo.pdkTableStatus.mTableStatus.MySeat - 1) + 1;
                    return mo.pdkTable.mIsRoomCreator && mo.pdkTableStatus.mTableStatus["SeatUser" + logicSeat] != null;
                };

                this.Button_kick1.setVisible(funcShowKick(1));
                this.Button_kick2.setVisible(funcShowKick(2));
            }
        } else if (index < 30) {
            //打牌
            if (index == 20) {
                this.Panel_caozuo.setVisible(true);
            } else if (index == 21) {
                this.Panel_caozuo.setVisible(false);
            }

        } else if (index < 40) {
            //打完了

        }


    },

    //设置该谁出牌
    setPlayerTime: function (seat, step) {
        if (seat > 2 && seat < 0) {
            this.Image_clock.setVisible(false);
            return;
        }

        if (step == 0) {
            this.Image_clock.setVisible(false);
            this.mCurrentSeat = null;
        } else if (step == 1) {
            if (this.mCurrentSeat == null || this.mCurrentSeat != seat) {
                if (mo.pdkCardHelper.clockPos != null) {
                    this.Image_clock.setVisible(true);
                    this.unschedule(this.updateClockDt);
                    this.AtlasLabel_clockDt = 20;
                    this.schedule(this.updateClockDt, 0.2);

                    //设置倒计时位置
                    var offset = cc.p(0, 0);
                    if (seat == 1) {
                        offset.x -= 70;
                    } else if (seat == 2) {
                        offset.x += 70;
                    }
                    this.Image_clock.setPosition(cc.pAdd(mo.pdkCardHelper.clockPos[seat], offset));
                }
            }

            this.mCurrentSeat = seat;
        }
    },

    //更新倒计时
    updateClockDt: function (dt) {
        this.AtlasLabel_clockDt -= dt;
        if (this.AtlasLabel_clockDt <= 0) {
            this.AtlasLabel_clockDt = 0;
        }

        this.AtlasLabel_clock.setString("" + parseInt(this.AtlasLabel_clockDt));
    },

    //更新自己能否出牌的状态
    updateChupaiBtnStatus: function (isPlay) {
        this.Button_chupai.setEnabled(isPlay);
        this.Button_chupai.loadTextureNormal(isPlay ? "res/ccs/pdk/btn/btn_bg_chupai1.png" : "res/ccs/pdk/btn/btn_bg_chpai2.png");
    },

    //更新自己提示信息
    updateTishiStatus: function (isMyFrist, isCanPlay) {
        if (isMyFrist) {
            this.mTuijianIndex = null;
            this.Button_tishi.setTouchEnabled(false);
            this.Button_tishi.loadTextureNormal("res/ccs/pdk/btn/btn_bg_tishi2.png");
        } else {
            if (isCanPlay) {
                this.mTuijianIndex = 0;
                this.Button_tishi.setTouchEnabled(true);
                this.Button_tishi.loadTextureNormal("res/ccs/pdk/btn/btn_bg_tishi1.png");
            } else {
                this.mTuijianIndex = -1;
                this.Button_tishi.setTouchEnabled(true);
                this.Button_tishi.loadTextureNormal("res/ccs/pdk/btn/btn_bg_fangqi1.png");
            }
        }
    },

    //输赢金币动画
    setScoreAnim: function (scores, hostSeat) {
        this.Panel_playeAnim.removeAllChildren();

        var delayTime = 1;
        //动画全
        for (var seat = 0; seat < 3; seat++) {
            var score = scores[seat];
            if (score == -9999) {
                continue;
            }

            this.mPlayer[seat].showAddScoreAnim(score, delayTime);
            if (seat != hostSeat) {
                if (score > 0) {
                    this.setScoreMovoTo(hostSeat, seat, delayTime);
                } else if (score != 0) {
                    this.setScoreMovoTo(seat, hostSeat, delayTime);
                }
            }
        }
        return delayTime + 1;
    },

    //飞金币
    setScoreMovoTo: function (formSeat, toSeat, delayTime) {
        cc.log("formSeat:" + formSeat);
        cc.log("toSeat:" + toSeat);
        var coins = [];
        for (var i = 0; i < 3; i++) {
            var coin = new cc.Sprite("res/ccs/pdk/gold.png");
            coin.setScale(0.6);
            coin.setVisible(false);
            this.Panel_playeAnim.addChild(coin);

            var posOffset = cc.p(Math.random() * 30 - 15, Math.random() * 30 - 15);
            var formPos = cc.pAdd(this.mPlayerPoss[formSeat], posOffset);
            var toPos = cc.pAdd(this.mPlayerPoss[toSeat], posOffset);
            var distance = cc.pDistance(formPos, toPos);
            var speed = 2000;
            time = distance / speed + i * 0.05 + delayTime;

            coin.setPosition(formPos);
            coin.runAction(cc.sequence(
                cc.delayTime(i * 0.05 + delayTime),
                cc.callFunc(function () {
                    mo.soundHelper.playPdkGetCoins();
                }, coin),
                cc.show(),
                cc.moveTo(0.5, toPos),
                cc.hide()
            ));
        }
    },

    //设置牌桌用户信息
    setTablePlayerInfos: function (infos) {
        this.mPlayerInfos = infos;
        for (var i = 0; i < 3; i++) {
            var player = this.mPlayer[i];
            var info = infos[i];
            if (info == null) {
                player.setVisible(false);
                continue;
            } else {
                player.setVisible(true);
            }

            if (info.user_info != null) {
                //head
                var Image_head = mo.seekWidgetByName(player, "Image_head");
                mo.gameHelper.loadImageForUrl(Image_head, info.user_info.faceUrl);

                //nick
                var Text_nick = mo.seekWidgetByName(player, "Text_nick");
                mo.gameHelper.setTextString(Text_nick, mo.gameHelper.getUserNickFilter(info.user_info.nickname));
            }

            //分数
            var Text_score = mo.seekWidgetByName(player, "Text_score");
            Text_score.stopAllActions();
            Text_score.setTag(info.RTScore);
            if (mo.pdkTableStatus.mTableStatus.Step == 0) {
                if (Text_score.getString() == "-999") {
                    mo.gameHelper.setTextString(Text_score, info.RTScore + "");
                } else {
                    Text_score.runAction(cc.sequence(
                        cc.delayTime(5),
                        cc.callFunc(function () {
                            mo.gameHelper.setTextString(this, this.getTag() + "");
                        }, Text_score)
                    ));
                }
            } else {
                mo.gameHelper.setTextString(Text_score, info.RTScore + "");
            }

            //准备状态
            var Image_ready = mo.seekWidgetByName(player, "Image_ready");
            if (mo.pdkTableStatus.mTableStatus.Step == 0 && info.State == 1) {
                if (this.mSeat == 0) {
                    Image_ready.setVisible(false);

                    var isPlay = mo.pdkTableStatus.mTableStatus.LeftPlayTimes != mo.pdkTable.mGameConfig.maxpan;
                    if (isPlay) {
                        Image_ready.setVisible(true);
                    }
                } else {
                    Image_ready.setVisible(true);
                }
            } else {
                Image_ready.setVisible(false);
            }

            //显示剩余牌
            var Image_leftCard = mo.seekWidgetByName(player, "Image_leftCard");
            Image_leftCard.setVisible(true);
            // Image_leftCard.setVisible(mo.pdkTableStatus.mTableStatus.Step == 1);
            if (mo.pdkTableStatus.mTableStatus.Step == 1) {
                var AtlasLabel_leftNum = mo.seekWidgetByName(Image_leftCard, "AtlasLabel_leftNum");
                AtlasLabel_leftNum.ignoreContentAdaptWithSize(true);
                var leftCard = info.LeftCards;
                AtlasLabel_leftNum.setString(leftCard + "");
            } else if (mo.pdkTableStatus.mTableStatus.Step == 0) {
                if (mo.pdkTable.mPlayGameCount == 0) {
                    Image_leftCard.setVisible(false);
                }
            }
        }
    },

    //chat
    setChatMsg: function (userChatMsg) {
        var seat = mo.pdkTableStatus.getViewSeatForUid(userChatMsg.uid);
        var Panel_chat = mo.seekWidgetByName(this.Panel_chat, "Panel_chat" + seat);
        Panel_chat.stopAllActions();

        var Image_chat = mo.seekWidgetByName(Panel_chat, "Image_chat");
        var Panel_audio = mo.seekWidgetByName(Panel_chat, "Panel_audio");
        var Text_content = mo.seekWidgetByName(Panel_chat, "Text_content");
        var Sprite_face = mo.seekWidgetByName(Panel_chat, "Sprite_face");

        Panel_chat.setVisible(false);
        Image_chat.setVisible(false);
        Sprite_face.setVisible(false);
        Panel_audio.setVisible(false);
        Text_content.setVisible(false);

        if (userChatMsg.type == 1) {
            //处理文字消息
            var numIndex = parseInt(userChatMsg.msg);

            if (numIndex >= 0 && numIndex < 13) {
                //播放音效
                var sex = mo.pdkTableStatus.getSexForUid(userChatMsg.uid);
                mo.soundHelper.playUserCustom(sex, numIndex);

                //快捷短语
                Text_content.setVisible(true);
                mo.gameHelper.setTextString(Text_content, mo.gameUserInfo.userCustomText[numIndex]);
                var sizeW = Text_content.getContentSize().width + 40;
                sizeW = Math.max(sizeW, 70);
                Text_content.setPositionX(sizeW / 2);

                Panel_chat.setVisible(true);
                Image_chat.setVisible(true);
                Image_chat.setContentSize(cc.size(sizeW, 64));

                Panel_chat.runAction(
                    cc.sequence(
                        cc.delayTime(3.0),
                        cc.hide()
                    )
                );
            } else if (numIndex >= 51 && numIndex < 80) {

                //表情
                Sprite_face.setVisible(true);
                var animation = new cc.Animation(mo.pdkCardHelper.getFaceFrames(numIndex - 51));
                animation.setDelayPerUnit(0.2);
                Sprite_face.stopAllActions();
                Sprite_face.runAction(cc.repeatForever(cc.animate(animation)));

                Panel_chat.setVisible(true);

                Panel_chat.runAction(
                    cc.sequence(
                        cc.delayTime(3.0),
                        cc.hide(),
                        cc.callFunc(function () {
                            Sprite_face.stopAllActions();
                        }, Panel_chat)
                    )
                );
            } else {
                Panel_chat.setVisible(false);

                var formSeat = seat;
                var toSeat = mo.pdkTableStatus.getViewForLogic(numIndex % 10, mo.pdkTableStatus.mTableStatus.MySeat - 1);
                var index = (parseInt(numIndex / 10) % 10);
                var p1 = this.mPlayerPoss[formSeat];
                var p2 = this.mPlayerPoss[toSeat];

                this.mPdkTablePlayerInfoLayer.showEffectChat(formSeat, toSeat, index, p1, p2);
            }
        } else {
            if (!cc.sys.isNative) {
                return;
            }

            //语音
            Panel_audio.setVisible(true);

            Panel_chat.setVisible(true);
            Image_chat.setVisible(true);
            Image_chat.setContentSize(cc.size(70, 64));

            //语音信息
            var intArray = [];
            var vmsg = userChatMsg.vmsg;
            var lenght = vmsg.limit - vmsg.offset;
            for (var i = 0; i < lenght; i++) {
                intArray.push(vmsg.view[i + vmsg.offset]);
            }

            var millisecond = mo.gameHelper.getMillisecond().toString();
            var fileName = millisecond + ".amr";
            mo.nativeHelper.playFile(fileName, intArray);

            var time = (lenght / 1500);
            Panel_chat.runAction(
                cc.sequence(
                    cc.delayTime(time),
                    cc.hide()
                )
            );
        }
    },

    //设置离线状态
    setPlayerOnlineStats: function (onlineInfo) {
        //重置
        for (var i = 0; i < 3; i++) {
            mo.seekWidgetByName(this.mPlayer[i], "Image_offline").setVisible(false);
        }

        //设置状态
        if (this.mPlayerInfos != null) {
            for (var i = 0; i < 3; i++) {
                if (this.mPlayerInfos[i] == null) {
                    continue;
                }
                var uid = this.mPlayerInfos[i].user_info.userid;

                if (onlineInfo[uid.toString()] != undefined && onlineInfo[uid.toString()] == 0) {
                    mo.seekWidgetByName(this.mPlayer[i], "Image_offline").setVisible(true);
                }
            }
        }
    },

    //发牌
    setFapaiAnim: function (cardNumss) {

    },

    //设置录像隐藏
    setIsReplay: function (isReplay) {
        mo.seekWidgetByName(this.ccsNode, "Button_setting").setVisible(!isReplay);
        mo.seekWidgetByName(this.ccsNode, "Button_chat").setVisible(!isReplay);
        this.mKwxSysInfoWidget.setVisible(!isReplay);
        if (this.mPdkTableMicLayer != null) {
            this.mPdkTableMicLayer.setVisible(!isReplay);
        }

    },

    //踢人
    setKickPlayerForViewSeat: function (viewSeat) {
        var logicSeat = mo.pdkTableStatus.getLogicForView(viewSeat, mo.pdkTableStatus.mTableStatus.MySeat - 1) + 1;
        var SeatUser = mo.pdkTableStatus.mTableStatus["SeatUser" + logicSeat];
        if (SeatUser != null) {
            mo.showMsgDialogOkAndCancel("确定要踢掉玩家[" + SeatUser.user_info.nickname + "]吗?", function () {
                mo.gameMsgManager.sendCreateUserKickOutRequestpdk(SeatUser.user_info.userid);
            }, this, function () {
            }, this);
        }
    },

    //礼包
    setChatMsgReward: function (userChatMsg) {
        var kwxRewardLayer = new KwxRewardLayer();
        this.addChild(kwxRewardLayer);
        var toPlayer = mo.pdkTableStatus.getViewSeatForUid(userChatMsg.uid);
        kwxRewardLayer.startAction(userChatMsg.msg, this.mPlayerPoss[toPlayer], toPlayer);
    }
});